/**
 * Tests for the model_choice.js file
 * 
 * Author: Chris Casola, Dan Robertson
 * 
 */

$(document).ready(function(){
	
	module("Tests for Choice class");
	
	test("testConstructChoice", function() {
		expect(4);
		var myChoice = new Choice(4);
		equal(4, myChoice.position,"tests that Choice.position is properly instantiated");
		equal(0, myChoice.leftEdges.length,"tests that Choice starts with an empty leftEdges array (for holding edges" );
		equal(0, myChoice.rightEdges.length,"tests that Choice starts with an empty rightEdges array");
		myChoice.label = "Terminator";
		equal("Terminator", myChoice.label, "checks if label is properly instantiated");
	});
	
	test("testAddEdge", function() {
		expect(7);
		var myChoice = new Choice(4);
		myChoice.addEdge(10, "left");
		ok(myChoice.leftEdges.length == 1,"checks that an edge has been placed in the right container");
		ok(myChoice.rightEdges.length == 0, "checks that an edge has not been placed in the improper container");
		ok(myChoice.leftEdges[0].vPos == 10,"verifies that the value of the edge stored is the same as the value entered");
		raises(function() {myChoice.addEdge(10, "asdf");},"Checks that you can only add an edge to the left or right");
		
		myChoice.addEdge(20, "right");
		ok(myChoice.rightEdges.length == 1,"verifies that an edge has been placed in the right container");
		ok(myChoice.leftEdges.length == 1, "verifies that an edge has been placed in the correct array");
		ok(myChoice.rightEdges[0].vPos == 20,"quick check to see that the right edge was stored (referenced by vPos");
	});
	
	test("testGetNextEdge", function () {
		expect(11);
		var myChoice = new Choice(4);
		equal(null, myChoice.getNextEdge(0),"checks that there are no edges associated with the new choice");
	
		myChoice.addEdge(5, "left");

		equal(null, myChoice.getNextEdge(5),"tests that getNextEdge doesnt return an edge lower then the input height");
		equal(5, myChoice.getNextEdge(0).vPos,"does getNextEdge(0) return an edge vPos?");
		equal("left", myChoice.side,"was the choice side constructed properly?");
		
		myChoice.addEdge(7, "right");
		equal(7, myChoice.getNextEdge(5).vPos,"more testing to verify that getNextEdge works");
		equal("right", myChoice.side,"was the choice side constructed properly?");
		
		equal(5, myChoice.getNextEdge(0).vPos,"is the edge still in the array?");
		
		myChoice.addEdge(8, "right");
		myChoice.addEdge(10, "left");
		
		equal(8, myChoice.getNextEdge(7).vPos, "checks that the edge was tied to the correct choice" );
		
		myChoice.addEdge(3, "left");
		
		equal(3, myChoice.leftEdges[0].vPos, "checks that edge was tied to the correct choice");
		equal(5, myChoice.leftEdges[1].vPos, "checks that edge was tied to the correct choice");
		equal(10, myChoice.leftEdges[2].vPos, "checks that edge was tied to the correct choice");
	});
	
	test("testAddEdge2", function () {
		expect(4);
		var myChoice = new Choice(4);
		myChoice.addEdge(5, "left");
		myChoice.addEdge(3, "right");
		myChoice.addEdge(8, "right");
		myChoice.addEdge(10, "left");

		equal(3, myChoice.rightEdges[0].vPos,"checks that edge was stored in the right choice");
		equal(8, myChoice.rightEdges[1].vPos,"checks that edge was stored in the right choice");
		equal(5, myChoice.leftEdges[0].vPos,"checks that edge was stored in the right choice");
		equal(10, myChoice.leftEdges[1].vPos, "checks that edge was stored in the right choice");
	});
	
	test("testGetPrevEdge", function () {
		expect(6);
		var myChoice = new Choice(4);
		equal(null, myChoice.getPrevEdge(0),"runs getPrevEdge on an empty choice");
		myChoice.addEdge(5, "left");

		equal(null, myChoice.getPrevEdge(5),"checks that getPrevEdge will return null when comparing equal height values ");
		equal(5, myChoice.getPrevEdge(7).vPos, "validates that getPrevEdge will return the right edge when passed a higher position");
		
		myChoice.addEdge(3, "right");
		equal(3, myChoice.getPrevEdge(5).vPos,"second check to see that getPrevEdge works with different values");

		myChoice.addEdge(8, "right");
		myChoice.addEdge(10, "left");
		equal(8, myChoice.getPrevEdge(10).vPos,"when passed an identical height to an existing edge, will return the edge 1 before that.");

		myChoice.addEdge(7, "left");

		equal(7, myChoice.getPrevEdge(8).vPos,"gets the previous edge entered");
	});
});